package 字母异位词分组;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

//按计数分类
public class Solution2 {
    public List<List<String>> groupAnagrams(String[] strs) {
        if(strs.length == 0 ){
            return  new ArrayList<>();
        }
        int[] arr = new int[26];
        HashMap<String, List> map = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            for (char c : chars) {
                arr[c-'a']++;
            }
            StringBuilder sb = new StringBuilder();
            for(int i = 0 ; i < 26 ; i++){
                sb.append('#');
                sb.append(arr[i]);
            }
            String key = sb.toString();
            if(!map.containsKey(key)) map.put(key,new ArrayList());
            map.get(key).add(str);
        }
        return new ArrayList<>(map.values());
    }
}
